<?php

//  Author: gangbo <daigangbo@126.com>

/**
 * 分类管理
 */
class TaxonomyAction extends AdminAction {
    /**
     * list page
     */
    public function index() {
        $Taxonomy = D('Taxonomy');
        $this->assign('catalogList',$Taxonomy->getList());
        $var = $Taxonomy->getList();
        $firephp = FirePHP::getInstance(true);
        // $var = array('i'=>10, 'j'=>20);
        $firephp->log($var, 'Iterators');
        $this->display();
    }
    /**
     * add
     */
    public function add() {
        $Taxonomy = D('Taxonomy');
        $catalogList = $this->formatList($Taxonomy->getList());
        $this->assign('catalogList',$catalogList);
        $this->display();
    }
    public function insert() {
        $Taxonomy = D('Taxonomy');
        $data=$Taxonomy->create();
        if( $data && $Taxonomy->insertNode($_POST['pid'],$data)) {
            $this->success();
        }else {
            $this->error(M()->getError());
        }
    }
    /**
     * 删除操作
     */
    public function delete(){
          $Taxonomy = D('Taxonomy');
         if($Taxonomy->deleteNode($_REQUEST['taxonomy_id'])){
             $this->success();
         }else{
             $this->error();
         }
    }
    /**
     * 对分类按格式组装
     * @param <type> $catalogList 
     */
    protected function formatList($catalogList) {
           $newList = array();
           foreach ($catalogList as $value){
               $newList[$value['taxonomy_id']] = $value['name'];
           }
           return $newList;
    }

}
?>